package biz.obake.team.touchprotector.tpservice;

import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import biz.obake.team.touchprotector.f.k;
import biz.obake.team.touchprotector.fingerprint.FingerprintActivity;
import biz.obake.team.touchprotector.g.c;
import java.util.Map;

public class TPService extends Service {

    /* renamed from: b  reason: collision with root package name */
    private a f1792b;

    /* renamed from: c  reason: collision with root package name */
    private String f1793c;

    /* renamed from: d  reason: collision with root package name */
    private SharedPreferences.OnSharedPreferenceChangeListener f1794d = new a();
    private c.b e = new b();
    private h f = new c();
    private h g = new d();
    private Handler h = new Handler();
    private String i = null;

    class a implements SharedPreferences.OnSharedPreferenceChangeListener {
        a() {
        }

        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
            TPService.this.j(str);
        }
    }

    class b implements c.b {
        b() {
        }

        public void onRamPrefsChanged(String str) {
            TPService.this.j(str);
        }
    }

    class c extends h {
        c() {
            super(TPService.this, (a) null);
        }

        /* access modifiers changed from: package-private */
        /* JADX WARNING: Can't fix incorrect switch cases order */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public void c(java.lang.String r7) {
            /*
                r6 = this;
                int r0 = r7.hashCode()
                r1 = 5
                r2 = 4
                r3 = 3
                r4 = 2
                r5 = 1
                switch(r0) {
                    case -2066548004: goto L_0x003f;
                    case -1674359176: goto L_0x0035;
                    case -1336169234: goto L_0x002b;
                    case 652452001: goto L_0x0021;
                    case 831789315: goto L_0x0017;
                    case 1744001669: goto L_0x000d;
                    default: goto L_0x000c;
                }
            L_0x000c:
                goto L_0x0049
            L_0x000d:
                java.lang.String r0 = "RequestChannel.Proximity"
                boolean r0 = r7.equals(r0)
                if (r0 == 0) goto L_0x0049
                r0 = 1
                goto L_0x004a
            L_0x0017:
                java.lang.String r0 = "Sensors.Paused"
                boolean r0 = r7.equals(r0)
                if (r0 == 0) goto L_0x0049
                r0 = 5
                goto L_0x004a
            L_0x0021:
                java.lang.String r0 = "RequestChannel.Normal"
                boolean r0 = r7.equals(r0)
                if (r0 == 0) goto L_0x0049
                r0 = 0
                goto L_0x004a
            L_0x002b:
                java.lang.String r0 = "RequestChannel.UpsideDown"
                boolean r0 = r7.equals(r0)
                if (r0 == 0) goto L_0x0049
                r0 = 2
                goto L_0x004a
            L_0x0035:
                java.lang.String r0 = "action_buttons"
                boolean r0 = r7.equals(r0)
                if (r0 == 0) goto L_0x0049
                r0 = 4
                goto L_0x004a
            L_0x003f:
                java.lang.String r0 = "TPService.State"
                boolean r0 = r7.equals(r0)
                if (r0 == 0) goto L_0x0049
                r0 = 3
                goto L_0x004a
            L_0x0049:
                r0 = -1
            L_0x004a:
                if (r0 == 0) goto L_0x005d
                if (r0 == r5) goto L_0x005d
                if (r0 == r4) goto L_0x005d
                if (r0 == r3) goto L_0x0057
                if (r0 == r2) goto L_0x0057
                if (r0 == r1) goto L_0x0057
                goto L_0x0092
            L_0x0057:
                biz.obake.team.touchprotector.tpservice.TPService r7 = biz.obake.team.touchprotector.tpservice.TPService.this
                r7.q()
                goto L_0x0092
            L_0x005d:
                java.lang.String r0 = "Stop"
                boolean r0 = r6.b(r0)
                if (r0 == 0) goto L_0x0069
                biz.obake.team.touchprotector.tpservice.TPService.o()
                goto L_0x0092
            L_0x0069:
                java.lang.String r0 = "Lock"
                boolean r0 = r6.b(r0)
                if (r0 == 0) goto L_0x0078
                biz.obake.team.touchprotector.tpservice.TPService r0 = biz.obake.team.touchprotector.tpservice.TPService.this
                r1 = 0
            L_0x0074:
                r0.i(r7, r1)
                goto L_0x0092
            L_0x0078:
                java.lang.String r0 = "Design"
                boolean r0 = r6.b(r0)
                if (r0 == 0) goto L_0x0085
                biz.obake.team.touchprotector.tpservice.TPService r0 = biz.obake.team.touchprotector.tpservice.TPService.this
                java.lang.String r1 = "design"
                goto L_0x0074
            L_0x0085:
                java.lang.String r0 = "Backlight"
                boolean r0 = r6.b(r0)
                if (r0 == 0) goto L_0x0092
                biz.obake.team.touchprotector.tpservice.TPService r0 = biz.obake.team.touchprotector.tpservice.TPService.this
                java.lang.String r1 = "backlight"
                goto L_0x0074
            L_0x0092:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.tpservice.TPService.c.c(java.lang.String):void");
        }
    }

    class d extends h {
        d() {
            super(TPService.this, (a) null);
        }

        /* access modifiers changed from: package-private */
        /* JADX WARNING: Can't fix incorrect switch cases order */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public void c(java.lang.String r7) {
            /*
                r6 = this;
                int r0 = r7.hashCode()
                r1 = 0
                r2 = 4
                r3 = 3
                r4 = 2
                r5 = 1
                switch(r0) {
                    case -2066548004: goto L_0x0035;
                    case -1336169234: goto L_0x002b;
                    case 652452001: goto L_0x0021;
                    case 831789315: goto L_0x0017;
                    case 1744001669: goto L_0x000d;
                    default: goto L_0x000c;
                }
            L_0x000c:
                goto L_0x003f
            L_0x000d:
                java.lang.String r0 = "RequestChannel.Proximity"
                boolean r7 = r7.equals(r0)
                if (r7 == 0) goto L_0x003f
                r7 = 1
                goto L_0x0040
            L_0x0017:
                java.lang.String r0 = "Sensors.Paused"
                boolean r7 = r7.equals(r0)
                if (r7 == 0) goto L_0x003f
                r7 = 4
                goto L_0x0040
            L_0x0021:
                java.lang.String r0 = "RequestChannel.Normal"
                boolean r7 = r7.equals(r0)
                if (r7 == 0) goto L_0x003f
                r7 = 0
                goto L_0x0040
            L_0x002b:
                java.lang.String r0 = "RequestChannel.UpsideDown"
                boolean r7 = r7.equals(r0)
                if (r7 == 0) goto L_0x003f
                r7 = 2
                goto L_0x0040
            L_0x0035:
                java.lang.String r0 = "TPService.State"
                boolean r7 = r7.equals(r0)
                if (r7 == 0) goto L_0x003f
                r7 = 3
                goto L_0x0040
            L_0x003f:
                r7 = -1
            L_0x0040:
                if (r7 == 0) goto L_0x0051
                if (r7 == r5) goto L_0x0051
                if (r7 == r4) goto L_0x0051
                if (r7 == r3) goto L_0x004b
                if (r7 == r2) goto L_0x004b
                goto L_0x0078
            L_0x004b:
                biz.obake.team.touchprotector.tpservice.TPService r7 = biz.obake.team.touchprotector.tpservice.TPService.this
                r7.q()
                goto L_0x0078
            L_0x0051:
                java.lang.String r7 = "Stop"
                boolean r7 = r6.b(r7)
                if (r7 == 0) goto L_0x005d
                biz.obake.team.touchprotector.tpservice.TPService.o()
                goto L_0x0078
            L_0x005d:
                java.lang.String r7 = "Unlock"
                boolean r7 = r6.b(r7)
                if (r7 == 0) goto L_0x006b
                biz.obake.team.touchprotector.tpservice.TPService r7 = biz.obake.team.touchprotector.tpservice.TPService.this
                r7.p(r1)
                goto L_0x0078
            L_0x006b:
                java.lang.String r7 = "UnlockForce"
                boolean r7 = r6.b(r7)
                if (r7 == 0) goto L_0x0078
                biz.obake.team.touchprotector.tpservice.TPService r7 = biz.obake.team.touchprotector.tpservice.TPService.this
                r7.p(r5)
            L_0x0078:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.tpservice.TPService.d.c(java.lang.String):void");
        }
    }

    class e implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ String f1799b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ String f1800c;

        e(String str, String str2) {
            this.f1799b = str;
            this.f1800c = str2;
        }

        public void run() {
            TPService.this.i(this.f1799b, this.f1800c);
        }
    }

    class f implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ boolean f1802b;

        f(boolean z) {
            this.f1802b = z;
        }

        public void run() {
            TPService.this.p(this.f1802b);
        }
    }

    class g implements Runnable {
        g() {
        }

        public void run() {
            TPService.this.q();
        }
    }

    private abstract class h {
        private h(TPService tPService) {
        }

        /* synthetic */ h(TPService tPService, a aVar) {
            this(tPService);
        }

        /* access modifiers changed from: package-private */
        public boolean a(String str, String str2) {
            return str2.equals(biz.obake.team.touchprotector.g.c.c(str));
        }

        /* access modifiers changed from: package-private */
        public boolean b(String str) {
            return a("RequestChannel.Normal", str) || a("RequestChannel.Proximity", str) || a("RequestChannel.UpsideDown", str);
        }

        /* access modifiers changed from: package-private */
        public abstract void c(String str);
    }

    private boolean d() {
        if (!biz.obake.team.touchprotector.c.e()) {
            biz.obake.team.touchprotector.c.u();
            biz.obake.team.touchprotector.log.a.b().d("Reject: Can't draw overlays");
            return false;
        } else if (biz.obake.team.touchprotector.g.a.g("no_lock_usb") && biz.obake.team.touchprotector.d.h.b.a()) {
            biz.obake.team.touchprotector.log.a.b().d("Reject: No lock on power");
            return false;
        } else if (biz.obake.team.touchprotector.g.a.g("lock_on_screen_off") && biz.obake.team.touchprotector.d.i.b.b()) {
            return true;
        } else {
            if (biz.obake.team.touchprotector.d.i.b.b()) {
                return false;
            }
            if (biz.obake.team.touchprotector.g.a.g("unlock_on_call") && biz.obake.team.touchprotector.d.g.b.c()) {
                biz.obake.team.touchprotector.log.a.b().d("Reject: Unlocking on phone calls");
                return false;
            } else if (!biz.obake.team.touchprotector.g.a.g("no_lock_landscape") || !biz.obake.team.touchprotector.c.p()) {
                String c2 = biz.obake.team.touchprotector.g.c.c("TPAS.FrontApp");
                biz.obake.team.touchprotector.nolockapps.a a2 = biz.obake.team.touchprotector.nolockapps.b.b().a(c2);
                if (a2 == null || !a2.f1772a) {
                    return true;
                }
                biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
                b2.d("Reject: NoLockApps: " + c2);
                return false;
            } else {
                biz.obake.team.touchprotector.log.a.b().d("Reject: No lock in landscape mode");
                return false;
            }
        }
    }

    private boolean e(boolean z) {
        if (!z && this.i == null) {
            return m() ? !k.j() && !k.n() : !biz.obake.team.touchprotector.e.a.e() || !k.n();
        }
        return true;
    }

    private void f(String str, String str2) {
        this.i = str2;
        k.l(this, str2);
        biz.obake.team.touchprotector.c.x();
        biz.obake.team.touchprotector.g.c.g("TPService.LockedBy", str);
        biz.obake.team.touchprotector.g.c.g("TPService.State", "Locked");
    }

    private void g() {
        k.p();
        biz.obake.team.touchprotector.c.x();
        biz.obake.team.touchprotector.g.c.g("TPService.State", "Unlocked");
    }

    public static void h(Map<String, String> map) {
        map.put("RequestChannel.Normal", "None");
        map.put("TPService.State", "Stopped");
        map.put("TPService.LockedBy", (Object) null);
        map.put("Sensors.Paused", "false");
    }

    /* access modifiers changed from: private */
    public void i(String str, String str2) {
        if (!biz.obake.team.touchprotector.c.s()) {
            this.h.post(new e(str, str2));
        } else if (d()) {
            f(str, str2);
        }
    }

    public static void k(String str, String str2) {
        l("RequestChannel.Normal", str, str2);
    }

    public static void l(String str, String str2, String str3) {
        String substring = str.startsWith("RequestChannel.") ? str.substring(15) : str;
        biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
        b2.d("Request: " + str2 + ", " + substring + ", " + str3);
        biz.obake.team.touchprotector.g.c.g(str, str2);
        biz.obake.team.touchprotector.g.c.g(str, "None");
    }

    private boolean m() {
        return biz.obake.team.touchprotector.donation.a.p() && biz.obake.team.touchprotector.e.a.c() && biz.obake.team.touchprotector.g.a.g("require_fingerprint") && FingerprintActivity.d() && FingerprintActivity.c();
    }

    public static void n(String str) {
        biz.obake.team.android.a a2 = biz.obake.team.android.a.a();
        Intent intent = new Intent(a2, TPService.class);
        if (str != null) {
            intent.putExtra("BY", str);
        }
        if (Build.VERSION.SDK_INT >= 26) {
            a2.startForegroundService(intent);
        } else {
            a2.startService(intent);
        }
    }

    public static void o() {
        biz.obake.team.android.a a2 = biz.obake.team.android.a.a();
        a2.stopService(new Intent(a2, TPService.class));
    }

    /* access modifiers changed from: private */
    public void p(boolean z) {
        if (!biz.obake.team.touchprotector.c.s()) {
            this.h.post(new f(z));
        } else if (e(z)) {
            g();
        }
    }

    /* access modifiers changed from: private */
    public void q() {
        if (biz.obake.team.touchprotector.c.s()) {
            this.f1792b.i();
        } else {
            this.h.post(new g());
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:19:0x006c, code lost:
        if (r0.equals("Unlocked") == false) goto L_0x0083;
     */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0086  */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x0096  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void j(java.lang.String r8) {
        /*
            r7 = this;
            int r0 = r8.hashCode()
            r1 = 0
            r2 = -1
            java.lang.String r3 = "TPService.State"
            r4 = -2066548004(0xffffffff84d2fadc, float:-4.960114E-36)
            if (r0 == r4) goto L_0x000e
            goto L_0x0016
        L_0x000e:
            boolean r0 = r8.equals(r3)
            if (r0 == 0) goto L_0x0016
            r0 = 0
            goto L_0x0017
        L_0x0016:
            r0 = -1
        L_0x0017:
            if (r0 == 0) goto L_0x001a
            goto L_0x004c
        L_0x001a:
            java.lang.String r0 = biz.obake.team.touchprotector.g.c.c(r3)
            if (r0 == 0) goto L_0x004c
            java.lang.String r4 = r7.f1793c
            boolean r4 = r0.equals(r4)
            if (r4 != 0) goto L_0x004c
            biz.obake.team.touchprotector.log.a r4 = biz.obake.team.touchprotector.log.a.b()
            java.lang.StringBuilder r5 = new java.lang.StringBuilder
            r5.<init>()
            java.lang.String r6 = "State: "
            r5.append(r6)
            java.lang.String r6 = r7.f1793c
            r5.append(r6)
            java.lang.String r6 = " -> "
            r5.append(r6)
            r5.append(r0)
            java.lang.String r5 = r5.toString()
            r4.d(r5)
            r7.f1793c = r0
        L_0x004c:
            java.lang.String r0 = biz.obake.team.touchprotector.g.c.c(r3)
            int r3 = r0.hashCode()
            r4 = -2013585622(0xffffffff87fb1f2a, float:-3.77846E-34)
            r5 = 2
            r6 = 1
            if (r3 == r4) goto L_0x0079
            r4 = -219666003(0xfffffffff2e829ad, float:-9.196916E30)
            if (r3 == r4) goto L_0x006f
            r4 = -146305277(0xfffffffff7478f03, float:-4.04753E33)
            if (r3 == r4) goto L_0x0066
            goto L_0x0083
        L_0x0066:
            java.lang.String r3 = "Unlocked"
            boolean r0 = r0.equals(r3)
            if (r0 == 0) goto L_0x0083
            goto L_0x0084
        L_0x006f:
            java.lang.String r1 = "Stopped"
            boolean r0 = r0.equals(r1)
            if (r0 == 0) goto L_0x0083
            r1 = 2
            goto L_0x0084
        L_0x0079:
            java.lang.String r1 = "Locked"
            boolean r0 = r0.equals(r1)
            if (r0 == 0) goto L_0x0083
            r1 = 1
            goto L_0x0084
        L_0x0083:
            r1 = -1
        L_0x0084:
            if (r1 == 0) goto L_0x0096
            if (r1 == r6) goto L_0x0093
            if (r1 != r5) goto L_0x008b
            goto L_0x009b
        L_0x008b:
            biz.obake.team.touchprotector.g.b r8 = new biz.obake.team.touchprotector.g.b
            java.lang.String r0 = "{9EE0C7AB-E685-4BE1-9A97-6A899F83A7B6}"
            r8.<init>(r0)
            throw r8
        L_0x0093:
            biz.obake.team.touchprotector.tpservice.TPService$h r0 = r7.g
            goto L_0x0098
        L_0x0096:
            biz.obake.team.touchprotector.tpservice.TPService$h r0 = r7.f
        L_0x0098:
            r0.c(r8)
        L_0x009b:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.tpservice.TPService.j(java.lang.String):void");
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

    public void onCreate() {
        a aVar = new a(this);
        this.f1792b = aVar;
        aVar.h();
        biz.obake.team.touchprotector.g.a.i().registerOnSharedPreferenceChangeListener(this.f1794d);
        biz.obake.team.touchprotector.g.c.e(this.e);
        this.f1793c = "Stopped";
        biz.obake.team.touchprotector.g.c.g("TPService.State", "Unlocked");
        biz.obake.team.touchprotector.d.c.a();
    }

    public void onDestroy() {
        k.a();
        biz.obake.team.touchprotector.d.c.b();
        biz.obake.team.touchprotector.g.a.i().unregisterOnSharedPreferenceChangeListener(this.f1794d);
        biz.obake.team.touchprotector.g.c.h(this.e);
        biz.obake.team.touchprotector.g.c.g("TPService.State", "Stopped");
        stopForeground(true);
    }

    public int onStartCommand(Intent intent, int i2, int i3) {
        if (intent == null) {
            return 1;
        }
        String stringExtra = intent.getStringExtra("BY");
        if (stringExtra != null) {
            biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
            b2.d("Started by " + stringExtra);
        }
        this.f1792b.i();
        return 1;
    }
}
